/*
 * @Author: hua
 * @Date: 2020-04-09 10:54:37
 * @description: 认证操作
 * @LastEditors: hua
 * @LastEditTime: 2020-07-28 11:28:39
 */
import request from '@/utils/Request';

/**
 * 获取生产批次
 */
export function getProductionBatch() {
    return request({
        url: '/lock/getProductionBatch',
        method: 'post',
    });
}

/**
 * 绑定大包装盒二维码
 * @param {Number} appUserId
 * @param {String} bigBoxQrCode
 * @param {String} smallBoxQrCode
 * @param {String} productionBatchId
 */
export function bindBigBoxQrCode(
    appUserId,
    bigBoxQrCode,
    smallBoxQrCode,
    productionBatchId,
) {
    return request({
        url: '/lock/bindBigBoxQrCode',
        method: 'post',
        data: { body: { appUserId, bigBoxQrCode, smallBoxQrCode, productionBatchId } },
    });
}

/**
 * 绑定外壳二维码
 * @param {Number} appUserId
 * @param {String} shellQrCode
 * @param {String} simcardImei
 * @param {String} productionBatchId
 */
export function bindShellQrCode(
    appUserId,
    shellQrCode,
    simcardImei,
    productionBatchId,
) {
    return request({
        url: '/lock/bindShellQrCode',
        method: 'post',
        data: { body: { appUserId, shellQrCode, simcardImei, productionBatchId } },
    });
}

/**
 * 绑定小包装盒二维码
 * 参数simcardImei、shellQrCode(绑定lock之后)可传任意一个
 * @param {Number} appUserId
 * @param {String} shellQrCode
 * @param {String} simcardImei
 * @param {String} smallBoxQrCode
 * @param {String} productionBatchId
 */
export function bindSmallBoxQrCode(
    appUserId,
    shellQrCode,
    simcardImei,
    smallBoxQrCode,
    productionBatchId,
) {
    return request({
        url: '/lock/bindSmallBoxQrCode',
        method: 'post',
        data: {
            body: {
                appUserId,
                shellQrCode,
                simcardImei,
                smallBoxQrCode,
                productionBatchId,
            },
        },
    });
}

/**
 * 保存测试记录
 * operationType: 传值 DD(响铃),OL(网络开锁),LC(关锁),RFID(rfid开锁),SLEEP(进入运输模式)可选
 * @param {String} productionBatchId
 * @param {Number} appUserId
 * @param {String} operationType
 * @param {Number} result
 * @param {String} simcardImei
 */
export function saveTestLog(
    productionBatchId,
    appUserId,
    operationType,
    result,
    simcardImei,
) {
    return request({
        url: '/lock/saveTestLog',
        method: 'post',
        data: {
            body: { productionBatchId, appUserId, operationType, result, simcardImei },
        },
    });
}

/**
 * 向锁发送指令
 * @param {Number} appUserId
 * @param {String} functionTag
 * @param {String} simcardImei
 * @param {String} deviceTypeName
 *
 * SLEEP 睡眠
 * OL 开锁
 * LC 关锁
 * DD 响铃
 */

export function sendCommand(appUserId, functionTag, simcardImei, deviceTypeName) {
    return request({
        url: '/lock/sendCommand',
        method: 'post',
        data: { body: { appUserId, functionTag, simcardImei, deviceTypeName } },
    });
}

/**
 * 获取锁信息
 * @param {Number} appUserId
 * @param {String} simcardImei
 * @param {String} shellQrCode
 */
export function getLock(appUserId, simcardImei, shellQrCode) {
    console.log({ body: { appUserId, simcardImei, shellQrCode } });
    return request({
        url: '/lock/getLock',
        method: 'post',
        data: { body: { appUserId, simcardImei, shellQrCode } },
    });
}

/**
 * 获取绑定信息
 * @param {Number} appUserId
 * @param {String} simcardImei
 */
export function getBoundInfo(appUserId, simcardImei) {
    return request({
        url: '/lock/getBoundInfo',
        method: 'post',
        data: { body: { appUserId, simcardImei } },
    });
}


/**
 * 获取已绑定后码锁分页列表
 * @param {String} shellQrCode
 * @param {String} simcardImei
 * @param {Number} pageNumber
 * @param {Number} pageSize
 * @param {String} orderBy
 * @param {String} sortBy
 */
export function getLockPage(shellQrCode, simcardImei, pageNumber, pageSize, orderBy, sortBy) {
    return request({
        url: '/lock/page',
        method: 'post',
        data: { body: { shellQrCode, simcardImei, pageNumber, pageSize, orderBy, sortBy } },
    });
}
